package cn.tedu.shoot;

import java.awt.image.BufferedImage;
import java.util.Random;

public class RandomFly extends FlyingObject implements EnemyScore {
    private int ySpeed;
    private int xSpeed;
    Random random = new Random();
    int num = random.nextInt(3)+1;

    public RandomFly(){
        super(100,70);
        y = random.nextInt(250)-70;
        x = random.nextInt(10)>=5 ? -width: World.WIDTH;
        if(x==-width){
            xSpeed = num;
        }else {
            xSpeed = -num;
        }
        ySpeed = (int)(Math.random()*5+2);
    }
    public void step() {//--------step()的处理
        y += ySpeed;   //y+(向下)
        x += xSpeed;
    }

    int index = 1;
    public BufferedImage getImage() {
        if(isLive()) {
            return Images.rfs[0];
        }else if(isDead()) {
            BufferedImage img = Images.rfs[index++];
            if(index== Images.bairs.length) {
                state = REMOVE;
            }
            return img;
        }
        return null;
    }

    public int getScore() {
        return 2;
    }
}
